package cn.icare.cms.controller;

import cn.icare.cms.OrderCommentService;
import cn.icare.cms.OrderService;
import cn.icare.cms.dao.po.Member;
import cn.icare.cms.model.enums.OrderStatusEnum;
import cn.icare.cms.model.ro.AddOrderCommentRO;
import cn.icare.cms.model.ro.AddShopCartRO;
import cn.icare.cms.model.vo.rest.RespMsgVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Classname OrderCommentController
 * @Description TODO
 * @Date 2020/4/1 19:56
 * @Created by Administrator
 */

@CrossOrigin
@RestController
@RequestMapping(value = "/rest/personal/ordercomment")
@Api(tags = "REST订单")
public class OrderCommentController extends BaseController {

    @Autowired
    private OrderCommentService commentService;

    @Autowired
    private OrderService orderService;

    @PostMapping()
    @ApiOperation(value = "订单评价-增加", notes = "订单评价-增加")
    public ResponseEntity<RespMsgVO> createOne(@RequestBody AddOrderCommentRO ro, HttpServletRequest request) {
        Member member = this.getCurrentUser(request);
        if (member == null) {
            return super.getRespFail("会员身份验证信息不正确");
        }
        Integer id = commentService.createOne(ro, member.getId(), member.getName());
        if (id > 0) {
            //更新订单状态
            orderService.updateStatus(ro.getOrderId(), OrderStatusEnum.FINISHED.getCode());
            return super.getRespOk(id);
        } else {
            return super.getRespFail("订单评价失败，请稍候再试");
        }
    }
}
